﻿@model ConferenceConcurrentEventAndFeeModel
@{
	ViewBag.Title = Resources.ConcurrentEventAndFee + ConstValues.strDash + ViewBag.ConferenceName;
}
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.EventName：<input id="eventName" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" onclick="searchData();">@Resources.Search</a>&nbsp;&nbsp;
		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceConcurrentEventAndFee, RoleType.添加))
		{
			<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-add" onclick="addData();" plain="true">@Resources.Create</a>
		}
	</div>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

@section bodyParts {
<div id="detailWindow" class="easyui-window"
	title="@Resources.ConcurrentEventAndFee" data-options="closed:true,minimizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="detailWindowTitle" class="tit01"></h3>
			<form id="frmDetail" method="post" enctype="multipart/form-data">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" id="tblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.ConferenceName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input type="hidden" id="hidId" name="id" />
							<input type="hidden" id="hidConferenceId" name="conferenceId" />
							<input id="txtConferenceName" disabled class="easyui-textbox" style="height:27px; width:300px;" value="@ViewBag.ConferenceName">

						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.EventName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtEventName" name="eventName" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['length[1,100]']">
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.EventTime：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtEventTime" name="eventTime" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['length[1,100]']">
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.EventPlace：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtEventPlace" name="eventPlace"  class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['length[1,100]']" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Link：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtLink" name="link" class="easyui-textbox" style="height:27px; width:300px;" data-options="validType:['length[1,100]']">
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.Contact：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtContact" name="contact"  class="easyui-textbox" style="height:27px; width:300px;" data-options="validType:['length[1,100]']" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.ContactPhoneMail：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtContactPhone" name="contactPhone" class="easyui-textbox" style="height:27px; width:300px;" data-options="validType:['length[1,100]']">
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.ChargeType：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="ddlChargeType" name="chargeType" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.GenericSelectionType.无">@Resources.SingleCharge</option>
								<option value="@ConstValues.GenericSelectionType.有">@Resources.MultipleCharge</option>
							</select>
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Status：</td>
						<td style="text-align: left;" class="w2 c2">
							<select id="ddlStatus" name="status" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.Status.正常">@Resources.Normal</option>
								<option value="@ConstValues.Status.暂停">@Resources.Pause</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.Sort：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtSort" name="sort" class="easyui-numberbox" style="height:27px; width:300px;" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Remark：</td>
						<td style="text-align: left;" class="w2 c4" colspan="3">
							<input id="txtRemark" name="remark" class="easyui-textbox" style="height:50px; width:892px;" data-options="multiline:true,validType:['length[1,1000]']" />
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="hdnWindowType" />
				<input type="button" class="gbtn" onclick="saveData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#detailWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
<div id="addFeeWindow" class="easyui-window"
	title="@Resources.AddFee" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="addFeeWindowTitle" class="tit01">@Resources.Create</h3>
			<form id="addFeeDetail" method="post" >
				@Html.AntiForgeryToken()
				<div id="secondGrid"></div>
				<table width="100%" height="100%" id="addFeeJudge" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.EventName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input type="hidden" id="eventId" name="eventId" />
							<input type="hidden" id="secondId" name="secondId" />
							<input type="hidden" id="hidIsAllIdentity" name="hidIsAllIdentity" />
							<input id="txtParentEventName" name="parentEventName" disabled class="easyui-textbox" style="height:27px; width:300px;">
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.Currency：</td>
						<td style="text-align: left;" class="w2 c2">
							<select id="selCurrency" name="currency" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.Currency.人民币">@Resources.RMB</option>
								<option value="@ConstValues.Currency.美元">@Resources.Dollar</option>
							</select>
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Price：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtPrice" name="Price" class="easyui-numberbox" style="height:27px; width:300px;" data-options="min:0,required:true,precision:2">
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.ApplicableIdentity：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="selAttendenceIdentity" name="AttendenceIdentityId" class="easyui-combobox" style="height:27px; width:300px;" data-options="required:true,multiple:true"></select>
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Number：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtNumber" name="Number" class="easyui-numberbox" style="height:27px; width:300px;" data-options="min:0,required:true">
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.Sort：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtSecondSort" name="txtSecondSort" class="easyui-numberbox" style="height:27px; width:300px;" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Status：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="ddlSecondStatus" name="ddlSecondStatus" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.Status.正常">@Resources.Normal</option>
								<option value="@ConstValues.Status.暂停">@Resources.Pause</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c3"></td>
						<td style="text-align: left;" class="w2 c4"></td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Remark：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="txtSecondRemark" name="txtSecondRemark" class="easyui-textbox" style="height:27px; width:892px;" data-options="validType:['length[1,100]']" />
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="hdnSecondWindowType" />
				<input type="button" class="gbtn" onclick="saveSecondData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#addFeeWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
}

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceConcurrentEventAndFee");
	common.setCurrentParentMenu("#menu_a1");

	var windowWidth = $(window).width() - 285;
	var windowHeight = $(window).height() - 110;

	$(function () {
		$("#eventName").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});
		$("#hidConferenceId").val("@Model.ConferenceId");

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceConcurrentEventAndFeeController.GetData),
					nameof(ConferenceConcurrentEventAndFeeController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
			method: "get",
			singleSelect: true,
			width: $(window).width() - 285,
			height: $(window).height() - 158,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			frozenColumns: [[
				{ field: "id", hidden: true },
				@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceConcurrentEventAndFee, RoleType.修改) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceConcurrentEventAndFee, RoleType.删除))
				{
					<text>
					{
						field: "operate", title: "@Resources.Operate", align: "center", width: 200,
						formatter: function(value, rec) {
							var strInfo = "";
							var tmp = rec.eventName == null ? "" : rec.eventName.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
							@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceConcurrentEventAndFee, RoleType.修改))
							{
								<text>
								strInfo += "<a href='#' style='color:#FF8C00;font-weight:bold;text-decoration:underline;' onclick='addFee(\""
									+ rec.id + "\",\""+ tmp + "\",\""+ rec.isAllIdentity + "\")'>@Resources.AddFee</a>&nbsp;|&nbsp;"
									+"<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editData(\""
									+ rec.id + "\")'>@Resources.Modify</a>";
								</text>
							}
							@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceConcurrentEventAndFee, RoleType.删除))
							{
								<text>
								if (strInfo != "") {
									strInfo += "&nbsp;|&nbsp;";
								}
								strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteData(\""
									+ rec.id + "\",\"" + tmp + "\")'>@Resources.Delete</a>";
								</text>
							}
							return strInfo;
						}
					},
					</text>
				}
				{ field: "eventName", title: "@Resources.EventName", align: "center", sortable: true, width: 300 },
			]],
			columns: [[					
				{ field: "eventTime", title: "@Resources.EventTime", align: "center", sortable: true, width: 150 },
				{ field: "eventPlace", title: "@Resources.EventPlace", align: "center", sortable: true, width: 150 },
				{
					field: "link", title: "@Resources.Link", align: "center", sortable: true, width: 300 ,
					formatter: function(value, rec) {
						if (rec.status == "@ConstValues.Status.正常") {
							if (value==null) {
								return "@ConstValues.strHyphen@ConstValues.strHyphen";
							} else {
								var conStr = ""
								conStr += "<a href='" + value + "' style='color:#1874CD;text-decoration:underline;' target='_blank'>" + value + "</a>  ";
								return conStr;
							}
						} else {
							return value;
						}
					}
				},
				{ field: "contact", title: "@Resources.Contact", align: "center", sortable: true, width: 150 },
				{ field: "contactPhone", title: "@Resources.ContactPhoneMail", align: "center", sortable: true, width: 300 },
				{
					field: "isAllIdentity", title: "@Resources.ChargeType", align: "center", width: 150 ,
					formatter: function(value, rec) {
				    		if (value) {
				    			return "@Resources.MultipleCharge";
				    		} else {
				    			return "@Resources.SingleCharge";
				    		}
					}
				},
				{
					field: "status", title: "@Resources.Status", align: "center", sortable: true, width: 100,
	                		formatter: function(value, rec) {
	                			if (value=="@ConstValues.Status.正常") {
	                				return "@Resources.Normal";
	                			} else {
	                				return "@Resources.Pause";
	                			}
	                		}
				},
				{ field: "sort", title: "@Resources.Sort", align: "center", sortable: true, width: 100 },
				{ field: "remark", title: "@Resources.Remark", align: "center", sortable: true, width: 200 },
				{ field: "creator", title: "@Resources.Creator", align: "center", sortable: true, width: 100 },
				{ field: "createIP", title: "@Resources.CreateIP", align: "center", sortable: true, width: 150 },
				{ field: "createDate", title: "@Resources.CreateDate", align: "center", sortable: true, width: 150 },
			]],
			onBeforeLoad: function(param) {
				param.conferenceId = $("#hidConferenceId").val();
				param.random = Math.random();
			}
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 158
			});
		});

		$("#detailWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});

		$("#addFeeWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},			
			top: ($(window).height() - 600) * 0.5
		});
	});

	function deleteData(id, name) {
		var confirmMessage = "@Resources.CfmDelete";
		confirmMessage = confirmMessage.replace(/\{0\}/g, name);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#hidId").val(id);
				$.post("@Url.Action(nameof(ConferenceConcurrentEventAndFeeController.Delete),
						nameof(ConferenceConcurrentEventAndFeeController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
					$("#frmDetail").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	};

	function addData() {
		$("#hdnWindowType").val("add");
		$("#detailWindowTitle").text("@Resources.Create");
		$("#txtSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtEventName").textbox("setValue","");
		$("#txtEventTime").textbox("setValue","");
		$("#txtEventPlace").textbox("setValue","");
		$("#txtLink").textbox("setValue","");
		$("#txtContact").textbox("setValue","");
		$("#txtContactPhone").textbox("setValue","");
		$("#txtRemark").textbox("setValue","");
		$("#ddlChargeType").combobox("setValue","");
		$("#detailWindowTitle").text("@Resources.Create");
		$("#detailWindow").window("open");
	}
		
	function editData(id) {
		var url = "@Url.Action(nameof(ConferenceConcurrentEventAndFeeController.GetEditData),
				nameof(ConferenceConcurrentEventAndFeeController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#dataGrid").datagrid("reload");
			} else {
				$("#txtEventName").textbox("setValue",data.data.eventName);
				$("#txtEventTime").textbox("setValue",data.data.eventTime);
				$("#txtEventPlace").textbox("setValue",data.data.eventPlace);
				$("#txtLink").textbox("setValue",data.data.link);
				$("#txtContact").textbox("setValue",data.data.contact);
				$("#txtContactPhone").textbox("setValue",data.data.contactPhone);
				$("#ddlStatus").combobox("setValue",data.data.status);
				$("#txtSort").numberbox("setValue", data.data.sort);
				$("#txtRemark").textbox("setValue",data.data.remark);
				$("#ddlChargeType").combobox("setValue",data.data.isAllIdentity);
				$("#hidId").val(id);
				$("#hdnWindowType").val("edit");
				$("#detailWindowTitle").text("@Resources.Modify");
				$("#detailWindow").window("open");
			}
		});
	}

	function saveData() {
		var isValid = $("#frmDetail").form("validate");

		if (isValid) {
			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});
					switch ($("#hdnWindowType").val())
					{
						case "add":
							$.post("@Url.Action(nameof(ConferenceConcurrentEventAndFeeController.Create),
									nameof(ConferenceConcurrentEventAndFeeController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
								$("#frmDetail").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										$("#detailWindow").window("close");
										$("#dataGrid").datagrid("reload");
									}
								}
							);
							break;
						case "edit":
							$.post("@Url.Action(nameof(ConferenceConcurrentEventAndFeeController.Modify),
									nameof(ConferenceConcurrentEventAndFeeController).GetControllerName(),new { ConferenceId = Model.ConferenceId })",
								$("#frmDetail").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										$("#detailWindow").window("close");
										$("#dataGrid").datagrid("reload");
									}
								}
							);
							break;
					}
				}
			})
		}
	};

	function searchData() {
		$("#dataGrid").datagrid("load", {
			eventName: $("#eventName").textbox("getValue")
		});
	}

	function addFee(id, eventName, isAllIdentity) {
		$("#eventId").val(id);
		$("#selCurrency").combobox("setValue","");
		$("#hidIsAllIdentity").val(isAllIdentity);
			
		$("#selAttendenceIdentity").combobox({
			editable: false,
			valueField: "id",
			multiple:true,
			textField: "identityName",
			url: "@Url.Action(nameof(UtilityController.GetAttendenceIdentityTypeApplicableForAll),
					nameof(UtilityController).GetControllerName())"
					+ "?conferenceId=" + $("#hidConferenceId").val()
					+ "&isAll="+isAllIdentity,
			onLoadSuccess: function(data) {
				orgCount = data.length;
				$(this).combobox("setText", "");
			},
			onShowPanel: function () {
				if (orgCount < 10) {
					$(this).combobox("panel").height("auto");
				} else {
					$(this).combobox("panel").height(200);
				}
			}
		});
			
		$("#txtParentEventName").textbox("setValue",eventName);
		$("#hdnSecondWindowType").val("add");
		$("#selAttendenceIdentity").combobox({multiple:true})
		$("#txtSecondSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtPrice").numberbox("setValue","");
		$("#txtNumber").numberbox("setValue","");
		$("#txtSecondRemark").textbox("setValue","");
		$("#secondGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceConcurrentEventAndFeeController.GetSecondData),
					nameof(ConferenceConcurrentEventAndFeeController).GetControllerName())"+"?id="+id,
			method: "get",
			checkOnSelect: false,
			selectOnCheck: false,
			height:199,
			nowrap: false,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			singleSelect: true,
			singleCheck: true,
			frozenColumns: [[
				{ field: "id", hidden: true },
				{ field: "chk", align: "center", checkbox: true },
				{
					field: "operate", title: "@Resources.Operate", align: "center", width: 150,
					formatter: function(value, rec,rowIndex) {
			    			var strInfo = "";
						var tmp = rec.attendenceIdentityId == null ? "" : rec.attendenceIdentityId.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
						strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editaddFee(\""
										+ rec.id + "\",\""+ rowIndex + "\")'>@Resources.Modify</a>&nbsp;|&nbsp;"									
			    			strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteSecondData(\""
							+ rec.id + "\",\"" + tmp + "\")'>@Resources.Delete</a>";
			    			return strInfo;
					}
				},
			]],
			columns: [[
				{ field: "attendenceIdentityId", title: "@Resources.ApplicableIdentity", align: "center", width: 150 },
				{ field: "price", title: "@Resources.Price", align: "center",  width: 150 },
				{ field: "currency", title: "@Resources.Currency", align: "center", width: 100 },
				{ field: "number", title: "@Resources.Number", align: "center", width: 150 },
				{
					field: "status", title: "@Resources.Status", align: "center", width: 150,
					formatter: function(value, rec) {
						if (value=="@ConstValues.Status.正常") {
							return "@Resources.Normal";
						} else {
							return "@Resources.Pause";
						}
					}
				},
				{ field: "sort", title: "@Resources.Sort", align: "center", sortable: true, width: 100 },
				{ field: "remark", title: "@Resources.Remark", align: "center", width: 200 },
			]],
			onBeforeLoad: function(param) {
				param.random = Math.random();
				param.conferenceId = $("#hidConferenceId").val();
			},
			onLoadSuccess: function(){
				$("#secondGrid").parent().find("div .datagrid-header-check").children("input[type=\"checkbox\"]").eq(0).attr("style", "display:none;");
			},
			onCheck: function (rowIndex, rowData) {
				editaddFee(rowData.id, rowIndex);
			},
			onUncheck: function (rowIndex, rowData) {
				initAddFeeForm();
			},
		});
		$("#addFeeWindowTitle").text("@Resources.AddFee");
		$("#addFeeWindow").window("open");
	}

	function saveSecondData() {
		var isValid = $("#addFeeDetail").form("validate");
			
		if (isValid) {
			var number = parseInt($("#txtNumber").numberbox("getValue"));
			if (number > 10 || number <= 0) {
				common.showError("@Resources.MsgLowerThanTen");
				return
			}

			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});
					switch ($("#hdnSecondWindowType").val())
					{
						case "add":
							$.post("@Url.Action(nameof(ConferenceConcurrentEventAndFeeController.CreateSecondData),
									nameof(ConferenceConcurrentEventAndFeeController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
								$("#addFeeDetail").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										initAddFeeForm()
										$("#secondGrid").datagrid("reload");
									}
								}
							);
							break;
						case "edit":
							$.post("@Url.Action(nameof(ConferenceConcurrentEventAndFeeController.ModifySecondData),
									nameof(ConferenceConcurrentEventAndFeeController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
								$("#addFeeDetail").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										initAddFeeForm()
										$("#secondGrid").datagrid("reload");
									}
								}
							);
							break;
							
					}
				}
			})
		}
	};

	function editaddFee(id, rowIndex) {
		$("input[name=chk]").attr("checked",false)
		$("input[type='checkbox']").eq(parseInt(rowIndex)+1).prop("checked", true);
		$("#secondId").val(id)
		$("#selAttendenceIdentity").combobox({multiple:false})
		var url = "@Url.Action(nameof(ConferenceConcurrentEventAndFeeController.GetSecondEditData),
				nameof(ConferenceConcurrentEventAndFeeController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#dataGrid").datagrid("reload");
			} else {
				$("#txtPrice").numberbox("setValue",data.data.fee);
				$("#txtNumber").numberbox("setValue",data.data.number);
				$("#selAttendenceIdentity").combobox("setValue",data.data.attendenceIdentityId);
				$("#selCurrency").combobox("setValue",data.data.currency);
				$("#ddlSecondStatus").combobox("setValue",data.data.status);
				$("#txtSecondSort").numberbox("setValue", data.data.sort);
				$("#txtSecondRemark").textbox("setValue",data.data.remark);
				$("#hdnSecondWindowType").val("edit");
			}
		});
	}

	function initAddFeeForm() {
		$("#txtSecondSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtPrice").numberbox("setValue","");
		$("#txtNumber").numberbox("setValue","");
		$("#selAttendenceIdentity").textbox("setValue","");
		$("#txtSecondRemark").textbox("setValue","");
		$("#selCurrency").combobox("setValue","");
		$("#ddlSecondStatus").combobox("setValue","@ConstValues.Status.正常");
		$("#hdnSecondWindowType").val("add");
		$("#selAttendenceIdentity").combobox({multiple:true})
	}

	function deleteSecondData(id, name) {
		$("#secondId").val(id);
		var confirmMessage = "@Resources.CfmDelete";
		confirmMessage = confirmMessage.replace(/\{0\}/g, name);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$.post("@Url.Action(nameof(ConferenceConcurrentEventAndFeeController.DeleteSecondData),
						nameof(ConferenceConcurrentEventAndFeeController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
					$("#addFeeDetail").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
			    				common.showError(data.message);
						} else {
			    				common.showSuccess(data.message, true);
			    				$("#secondGrid").datagrid("reload");
			    				initAddFeeForm();
						}
					}
				);
			}
		});
	};	
</script>
}